<template>
  <div>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td>商铺名称</td>
          <td>
            <input type="text" v-model="info.sname" />
          </td>
        </tr>
        <tr>
          <td>商铺楼层</td>
          <td>
            <select v-model="info.slou">
              <option value="">请选择</option>
              <option :value="1">l楼</option>
              <option :value="2">2楼</option>
              <option :value="3">3楼</option>
              <option :value="4">4楼</option>
            </select>
          </td>
        </tr>
        <tr>
          <td>业主</td>
          <td>
            <input type="text" v-model="info.uname" />
          </td>
        </tr>
        <tr>
          <td>联系电话</td>
          <td>
            <input type="text" v-model="info.sphone" />
          </td>
        </tr>
        <tr>
          <td>商铺状态</td>
          <td>
            <select v-model="info.tid">
              <option :value="0">请选择</option>
              <option v-for="a in infos.list" :value="a.tid">
                {{ a.tname }}
              </option>
            </select>
          </td>
        </tr>
        <tr>
          <td></td>
          <td>
            <input type="button" value="确定" @click="update" />
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import axios from "axios";
import { reactive, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
const route = useRoute();
const router = useRouter();
let info: any = reactive({
  sid: route.query.sid,
  sname: "",
  slou: 0,
  uname: "",
  sphone: "",
  tid: 0,
  stime: "2025-05-13T02:18:35.843Z",
  lJid: 1,
});
let infos: any = reactive({
  list: [],
});
onMounted(() => {
  lists();
  find();
});

const find = () => {
  axios({
    url: "/api/Shop/Find",
    method: "get",
    params: {
      sid: route.query.sid,
    },
  }).then((res) => {
    console.log(res);
    Object.assign(info, res.data);
  });
};
const lists = () => {
  axios({
    url: "/api/Shop/GetType",
    method: "get",
  }).then((res) => {
    console.log(res);
    infos.list = res.data;
  });
};
const update = () => {
  if (info.sname == "") {
    alert("商铺名称不能为空");
    return;
  }
  if (info.slou == "") {
    alert("楼层不能为空");
    return;
  }
  if (info.uname == "") {
    alert("业主不能为空");
    return;
  }
  if (info.sphone == "") {
    alert("手机号不能为空");
    return;
  }
  if (info.tid == "") {
    alert("商铺状态不能为空");
    return;
  }
  axios({
    url: "/api/Shop/Update",
    method: "put",
    data: info,
  }).then((res) => {
    if (res.data == -1) {
      alert("手机号不能重复");
      return;
    }
    if (res.data > 0) {
      alert("修改成功");
      location.href = "/listshop";
      return;
    } else {
      alert("修改失败");
      return;
    }
  });
};
</script>

<style scoped></style>
